
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>使用MP后CRUD的SQL语句是如何生成的？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>使用MP后CRUD的SQL语句是如何生成的？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">使用MyBatis-Plus进行数据访问层开发相较于传统方式，其主要优势是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">MyBatis-Plus的主要优势在于它能够自动化生成CRUD（增删改查）的SQL语句。它在运行时会根据实体类和其映射关系自动生成相应的SQL，从而大大简化了数据访问层的开发工作。</div>
          </div>
          <div class="card-source">来源: 文档开篇部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">MyBatis-Plus中哪个核心接口提供了常用的CRUD方法？请列举至少三个。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">MyBatis-Plus提供了 `BaseMapper` 接口，其中包含了常用的CRUD方法，例如 `selectById`, `insert`, `updateById`, 和 `deleteById`。</div>
          </div>
          <div class="card-source">来源: 1. 基本操作方法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当调用MyBatis-Plus的 `insert(entity)` 方法时，它如何生成SQL语句？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">调用 `insert(entity)` 方法时，MyBatis-Plus会生成一个 `INSERT INTO` 语句，其表名根据实体类映射，插入的字段和值则来源于实体类中的属性值。例如：`INSERT INTO user (name, age) VALUES (#{name}, #{age})`。</div>
          </div>
          <div class="card-source">来源: 2. b. 插入记录 insert</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在MyBatis-Plus中，如果需要构建复杂的查询条件（例如 `name = 'John' AND age > 18`），应该使用什么工具？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该使用条件构造器，如 `QueryWrapper`。通过调用其 `eq` (等于) 和 `gt` (大于) 等方法，可以构建复杂的查询条件，MyBatis-Plus会根据这些条件生成相应的SQL语句。</div>
          </div>
          <div class="card-source">来源: 3. 条件构造器</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">MyBatis-Plus的逻辑删除功能是如何工作的？调用 `deleteById` 方法时会发生什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当配置了逻辑删除后，调用 `deleteById` 方法不会生成物理删除的 `DELETE` 语句，而是会生成一个 `UPDATE` 语句来修改逻辑删除字段的状态。例如，它会生成类似 `UPDATE user SET deleted = 1 WHERE id = 1` 的SQL。</div>
          </div>
          <div class="card-source">来源: 5. 逻辑删除</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">MyBatis-Plus的分页插件是如何实现分页查询的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">MyBatis-Plus的分页插件会自动处理分页查询，通过在生成的SQL语句末尾添加分页相关的SQL语法（如 `LIMIT` 子句）来实现。例如，查询第一页，每页10条记录，会生成类似 `SELECT * FROM user LIMIT 0, 10` 的SQL。</div>
          </div>
          <div class="card-source">来源: 4. 分页查询</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
